package com.clkj.xiuzheng.dao;

import com.clkj.xiuzheng.pojo.OutStock;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author yawang
 * @create 2024/04/18 15:53:39
 **/
@Repository
public interface OutStockMapper extends Mapper<OutStock> {
    @Insert("insert into t_cl_outStock values (#{customerId},#{userId},#{productNum},#{totalMoney},#{invoice},#{outNote},#{outNumber},#{outDate},#{applyStatus},#{companyId},#{logisticsCompany},#{logisticsTracking},#{shippingStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "outId")
    void addOutStock(OutStock outStock);

    /**
     * 获取销售出库朱单据最大id
     *
     * @return
     */
    @Select("select Max(out_id) from t_cl_outStock ")
    Integer getMaxId();

    @Select("select a.*,b.customer_shopName,b.customer_address,b.customer_tel,b.customer_img from t_cl_outStock a left join t_cl_customer b on a.customer_id = b.customer_id " +
            "where a.user_id = #{userId} order by a.out_id desc ")
    List<OutStock> outStockListBySeven(@Param("userId")Integer userId);

    @Select("select SUM(total_money) from t_cl_outStock  where user_id = #{userId} and DateDiff(day,out_date,getDate())<=1")
    Double getTodaySales(@Param("userId") Integer userId);
    @Select("select SUM(total_money) from t_cl_outStock  where user_id = #{userId} and DateDiff(day,out_date,getDate())<=30")
    Double getMonthSales(Integer userId);

    @Select("select a.*,b.customer_name,c.user_name from t_cl_outStock a left join t_cl_customer b on a.customer_id = b.customer_id " +
            "left join t_cl_user c on a.user_id = c.user_id " +
            " where a.company_id = #{companyId}" +
            " order by a.out_id desc")
    List<OutStock> getOutStock(@Param("companyId")Integer companyId);

}
